using Microsoft.EntityFrameworkCore;
using UniversalAdmin.Domain.Entities;


namespace UniversalAdmin.Infrastructure.Data.Contexts
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) {} //数据库上下文的构造函数
    
        // 实体表映射到数据库(告诉数据库应该有哪些表)
        public DbSet<User> Users  => Set<User>();
        public DbSet<Role> Roles  => Set<Role>();
        public DbSet<Menu> Menus  => Set<Menu>();
        public DbSet<SystemConfig> SystemConfigs  => Set<SystemConfig>();
        public DbSet<OperatingSystem> OperatingSystems  => Set<OperatingSystem>();


        //数据库表设计蓝图
        protected override void OnModelCreating(ModelBuilder modelBuilder) //OnModelCreating 是 “把实体翻译成数据库表结构” 的入口函数
        {
                modelBuilder.Entity<User>().ToTable("users");
                modelBuilder.Entity<Role>().ToTable("roles");
                modelBuilder.Entity<Menu>().ToTable("menus");
                modelBuilder.Entity<OperationLog>().ToTable("operating_logs");
                modelBuilder.Entity<SystemConfig>().ToTable("system_configs");
                
        }
    }
    

}